#include "math_utils.h"
#include <ctime>
#include <random>

#ifndef M_PI
#define M_PI 3.1415926
#endif

namespace kanon
{
    uint32_t RandomGenerator::seed = 0;

    void RandomGenerator::init()
    {
        time_t cur_time = time(NULL);
        srand((uint32_t)cur_time);
    }

    float RandomGenerator::random_float(float min, float max)
    {
        float v = (float)rand() / RAND_MAX;
        return v * (max - min) + min;
    }

    glm::vec2 RandomGenerator::random_disk(float radius)
    {
        std::random_device rd;
        std::mt19937 gen(rd());
        std::uniform_real_distribution<> dis(0.0, 1.0);

        double theta = 2.0 * M_PI * dis(gen);
        double u = dis(gen);
        double r = std::sqrt(u);
        glm::vec2 pt;
        pt.x = radius * std::cos(theta);
        pt.y = radius * std::sin(theta);
        return pt;
    }

}